package com.away.sequence;

import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
@RocketMQMessageListener(topic = "test_topic",consumerGroup = "away_test",consumeMode = ConsumeMode.ORDERLY,consumeThreadMax = 1)
//consumeMode 一个队列对应一个线程  //线程回收问题
public class SequenceMessageConsumer implements RocketMQListener<MessageExt> {


    @Override
    public void onMessage(MessageExt message) {
        Random rand = new Random();
        try {
            Thread.sleep(rand.nextInt(1000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"-> 队列:"+message.getQueueId()+" ->message:"+new String(message.getBody()));
    }
}
